/**
 * 
 */
package com.eclipse.org.snms;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.ArrayList;

/**
 * @author tim, david, toufic
 *
 */
public class TaskComposite extends StickyNote {
	/**
	 * This Class symbolizes a single TaskStep of the StickyNote
	 */
	
	//Variables
	private String title;
	private Calendar deadline = Calendar.getInstance();
	private int priority; 		//from 1 (low prio) to 5 (high prio)
	private ArrayList<StickyNote> stickyNotes = new ArrayList<StickyNote>();
	private int isActive;
	
	public TaskComposite(){
		super();
	}
	
	public TaskComposite(String title, Calendar deadline, int priority, int isActive) {
		// TODO Auto-generated constructor stub
		this.title = title;
		this.deadline = deadline;
		
		if (isActive>=1 && isActive<=5) { //Prio 1 = low  | Prio 5 = high
			this.priority = priority;
		} else throw new UnsupportedOperationException();
		
		if (isActive>=0 && isActive<=2) { //0 = Inactive | 1 = Active | 2 = deleted
			this.isActive = isActive;
		} else throw new UnsupportedOperationException();
	}	
	
	public void add(StickyNote stickyNote) {
		stickyNotes.add(stickyNote);		
	}
	
	public void remove(StickyNote stickyNote) {
		if (stickyNotes.indexOf(stickyNote)>0) {
			stickyNotes.remove(stickyNote);
		}
	}
		
	//to traverse through the StickyNotes, just hand over a counter
	public StickyNote getchild(int i) {
		return (StickyNote)stickyNotes.get(i);
	}

/* getter Methods*/		
	public String getTitle() {
		return title;
	}
	
	public Calendar getDeadline() {
		return deadline;
	}
	
	public int getPriority() {
		return priority;
	}

	public int getIsActive() {
		return isActive;
	}
	
/* setter Methods*/
	public void setTitle(String title) {
		this.title = title;
	}
	
	public void setDeadline(Calendar deadline) {
		this.deadline = deadline;
	}
	
	public void setPriority(int priority) {
		if (priority>=1 && priority<=5) { //Prio 1 = low  | Prio 5 = high
			this.priority = priority;
		} else throw new UnsupportedOperationException();
	}

	public void setIsActive(int isActive) {
		if (isActive>=0 && isActive<=2) { //0 = Inactive | 1 = Active | 2 = deleted
			this.isActive = isActive;
		} else throw new UnsupportedOperationException();
	}	
	
	public String Serialiaze(){
		SimpleDateFormat sdf = new SimpleDateFormat(
				"yyMMddHHmmssZ");
		String xml="<task>\n";
		xml+= "<id>"+this.getId()+"</id>\n";
		xml+= "<title>"+this.getTitle()+"</title>\n";
		xml+= "<description>"+this.getDescription()+"</description>\n";
		xml+= "<deadline>"+sdf.format(this.getDeadline().getTime())+"</deadline>\n";
		xml+= "<isActive>"+this.getIsActive()+"</isActive>\n";
		xml+= "<priority>"+this.getPriority()+"</priority>\n";
		for(StickyNote stickyNote:stickyNotes){
			xml+= stickyNote.Serialiaze();
		}
		xml+="</task>\n";
		return xml;
	}

}
